package com.easyaop.api.pointcut;

import java.util.List;
import java.util.stream.Collectors;

import com.easyaop.api.pointcut.MethodObject;

import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;

public class MethodObjectForBuddy implements MethodObject {
        private MethodDescription method;

        public MethodObjectForBuddy(MethodDescription method) {
            this.method = method;
        }

        @Override
        public String getClassName() {
            return method.getDeclaringType().getActualName();
        }

        @Override
        public String getName() {
            return method.getName();
        }

        @Override
        public String getDescriptor() {
            return method.getDescriptor();
        }

        @Override
        public List<String> getAnnotations() {

            AnnotationList annotations = method.getDeclaredAnnotations();

            return annotations.stream().map(AnnotationDescription::getAnnotationType)
                    .map(TypeDescription::getName)
                    .collect(Collectors.toList());

//            return Arrays.stream(method.getAnnotations()).map(Annotation::annotationType)
//                    .map(Class::getName).collect(Collectors.toList());
//            return null;
        }
    }